﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ganaye.EmbeddedDb
{
    class TableEnumerator : IEnumerator, IDisposable
    {
        protected Table mTable;
        private UInt32 mCurrentRecordNo;

        public TableEnumerator(Table table)
        {
            mTable = table;
            ((IEnumerator)this).Reset();
        }

        #region IDisposable Members

        void IDisposable.Dispose()
        {
            //throw new NotImplementedException();
        }

        #endregion

        #region IEnumerator Members

        object System.Collections.IEnumerator.Current
        {
            get { return mTable.GetRecord(mCurrentRecordNo); }
        }

        bool System.Collections.IEnumerator.MoveNext()
        {
            mCurrentRecordNo = (mCurrentRecordNo == UInt32.MaxValue ? 0 : mCurrentRecordNo + 1);
            return mCurrentRecordNo < mTable.RecordCount;
        }

        void System.Collections.IEnumerator.Reset()
        {
            mCurrentRecordNo = UInt32.MaxValue;
        }

        #endregion
    }

    class TableEnumerator<T> : TableEnumerator, IEnumerator<T> where T : Record
    {
        public TableEnumerator(Table<T> table)
            : base(table)
        {

        }

        #region IEnumerator<T> Members

        T IEnumerator<T>.Current
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
}
